<?php

    header('content-type:text/html;charset="utf-8') ;
    
    $host = 'localhost:3306';
    $name = 'root';
    $pwd = 'root';
    $dbname = 'test2';
    $conn = mysqli_connect($host , $name , $pwd , $dbname);

    if(!$conn) {
        die('数据库连接失败');
    }


    $kw = $_GET['kw'] ;

    $sortName = $_GET['sortName'] ;

    $sortType = $_GET['sortType'] ;

    $obj = [] ;
    


    $sql = "select * from goods_list where goods_des like '%$kw%' order by $sortName $sortType";
    // 默认只会转第一条数据
    $res = mysqli_query($conn , $sql) ;

    $list = [] ;

    while($data = mysqli_fetch_array($res)) {
        $temp = [] ;
        $temp['id'] = $data['goods_id'] ;
        $temp['name'] = $data['goods_name'] ;
        $temp['title'] = $data['goods_title'] ;
        $temp['des'] = $data['goods_des'] ;
        $temp['img'] = $data['goods_img'] ;
        $temp['price'] = $data['goods_price'] ;
        $temp['type'] = $data['goods_type'] ;
        array_push($list , $temp) ;
    }

    if($list) {
        $obj['status'] = true ;
        $obj['msg'] = '数据请求成功';
        $obj['data'] = $list ;
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '服务器错误';
        $obj['data'] = $list ;
    }

    echo(json_encode($obj , JSON_UNESCAPED_UNICODE));